package com.example.li.myapplication.dagger;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.example.li.myapplication.R;

import javax.inject.Inject;

public class DaggerActivity extends AppCompatActivity {
    @Inject
    HelloDagger helloDagger;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dagger);
       useDagger();
    }


    private void useDagger() {
        ActivityComponent activityComponent = DaggerActivityComponent.create();
        // 注入
        activityComponent.inject(this);//@Component(modules = ActivityModule.class)
        //是@Inject和@Module的桥梁，它的主要作用就是连接这两个部分。
        TextView tv = (TextView) findViewById(R.id.text);
        tv.setText(helloDagger.user.name+"");
    }
}
